﻿using System;

namespace CommonLibrary.Helpers
{
    public class DataSetHelper
    {
        public static Random R { get; set; } = DataSet.R;

        public static void RandomGenerateArrivalAndDueTime(bool randomFlag = false)
        {
            if (DataSet.ArrivalTime == null || DataSet.ArrivalTime.Length == 0) return;
            if (DataSet.DueTime == null || DataSet.DueTime.Length == 0) return;
            DataSet.ArrivalTime[0] = 0;
            DataSet.DueTime[0] = 700;
            for (int i = 0; i < DataSet.NumEMU - 1; i++)
            {
                DataSet.ArrivalTime[i + 1] = DataSet.ArrivalTime[i] + DataSet.R.Next(2 * DataSet.SafeTimeInterval, 4 * DataSet.SafeTimeInterval);
                DataSet.DueTime[i + 1] = DataSet.DueTime[i] + DataSet.R.Next(2 * DataSet.SafeTimeInterval, 4 * DataSet.SafeTimeInterval);
            }
        }

        public static void Init()
        {
            DataSet.OpeBelongEMU = new int[DataSet.NumOperation];
            DataSet.OpeBelongJob = new int[DataSet.NumOperation];
            DataSet.StandardTime = new int[DataSet.NumOperation];
            DataSet.JobType = new int[DataSet.NumEMU];

            for (int i = 0; i < DataSet.NumEMU; i++)
            {
                DataSet.OpeBelongEMU[5 * i] = i;
                DataSet.OpeBelongEMU[5 * i + 1] = i;
                DataSet.OpeBelongEMU[5 * i + 2] = i;
                DataSet.OpeBelongEMU[5 * i + 3] = i;
                DataSet.OpeBelongEMU[5 * i + 4] = i;

                DataSet.OpeBelongJob[5 * i] = 0;
                DataSet.OpeBelongJob[5 * i + 1] = 1;
                DataSet.OpeBelongJob[5 * i + 2] = 2;
                DataSet.OpeBelongJob[5 * i + 3] = 2;
                DataSet.OpeBelongJob[5 * i + 4] = 2;

                DataSet.StandardTime[5 * i] = DataSet.MaintenanceTime;
                DataSet.StandardTime[5 * i + 1] = DataSet.WashTime;
                DataSet.StandardTime[5 * i + 2] = 0;
                DataSet.StandardTime[5 * i + 3] = 0;
                DataSet.StandardTime[5 * i + 4] = 0;

                DataSet.JobType[i] = i == DataSet.NumEMU - 1 ? 1000 : 0;
            }

            DataSet.TrackNumOfJob = new[] { DataSet.NumEquipmentRepair, DataSet.NumEquipmentWash, DataSet.NumEquipmentStore };//每种作业有多少股道
            DataSet.TrackCostOfJob = new[] { 4000, 4000, 2000 };//股道惩罚

            //RandomGenerateArrivalAndDueTime();
        }
    }
}